package businessLayer;

import presentationLayer.PrincipalView;
import presentationLayer.managerView.ManagerView;
import presentationLayer.pastryCookView.PastryCookView;
import businessLayer.businessObjects.CustomersBusinessObject;
import businessLayer.businessObjects.IngredientsBusinessObject;
import businessLayer.businessObjects.PiesBusinessObject;
import businessLayer.businessObjects.RecipesBusinessObject;
import businessLayer.businessObjects.UsersBusinessObject;
import dataAccessLayer.abstractFactory.Factory;

public class Facade 
{
	private final int MANAGER_USER = 1;
	private final int PASTRYCOOK_USER = 2;
	private final int SELLER_USER = 3;
	
	private int currentUserType;
	private String currentUserName;
	//private int currentUserCode;
	
	private Factory factory;
	
	private UsersBusinessObject usersBusinessObject;
	private IngredientsBusinessObject ingredientsBusinessObject;
	private CustomersBusinessObject customersBusinessObject;
	private RecipesBusinessObject recipesBusinessObject;
	private PiesBusinessObject piesBusinessObject;
	
	private PrincipalView principalView;
	private ManagerView managerView;
	private PastryCookView pastryCookView;
	
	public Facade() 
	{
		currentUserType = -1;
		
		factory = Factory.getInstance();
		
		usersBusinessObject = new UsersBusinessObject( factory );
		ingredientsBusinessObject = new IngredientsBusinessObject( factory );
		customersBusinessObject = new CustomersBusinessObject( factory );
		recipesBusinessObject = new RecipesBusinessObject( factory );
		piesBusinessObject = new PiesBusinessObject( factory );
	}

	public boolean authenticUser(String userName, String password)
	{
		boolean success = false;
		
		success = usersBusinessObject.authenticUser( userName , password );

		return success;
	}

	public void deployView() 
	{
		currentUserType = usersBusinessObject.getCurrentUserType();
		currentUserName = usersBusinessObject.getCurrentUserName();
		//currentUserCode = usersBusinessObject.getCurrentUserCode();
		
		switch(currentUserType)
		{
		
		case MANAGER_USER:
			managerView = new ManagerView(this,currentUserName);
			managerView.setVisible(true);
			break;
			
		case PASTRYCOOK_USER:
			pastryCookView = new PastryCookView(this,currentUserName);
			pastryCookView.setVisible(true);
			break;
			
		case SELLER_USER:
			break;
		}
	}
	
	public void setPrincipalView(PrincipalView principalView) 
	{
		this.principalView = principalView;
	}

	public void showPrincipalView() 
	{
		principalView.cleanFields();
		principalView.setVisible(true);
	}

	public Object[][] getUsers() 
	{
		return usersBusinessObject.getUsers();
	}

	public Object[][] getIngredients() 
	{
		return ingredientsBusinessObject.getIngredients();
	}

	public Object[][] getCustomers() 
	{
		return customersBusinessObject.getCustomers();
	}

	public boolean insertCity(String newCity) 
	{
		return usersBusinessObject.insertCity(newCity);
	}

	public boolean insertUser(String firstName, String lastName,int identification, String address, int city, String telephone,String userName, String password, int userType) 
	{
		return usersBusinessObject.insertUser(firstName, lastName, identification, address, city, telephone, userName, password, userType);
	}

	public String[] getCitiesData() 
	{
		return usersBusinessObject.getCities();
	}

	public String[] getMeasureUnitiesData() 
	{
		return ingredientsBusinessObject.getMeasureUnities();
	}

	public boolean insertMeasureUnity(String newMeasureUnity) 
	{
		return ingredientsBusinessObject.insertMeasureUnity(newMeasureUnity);
	}

	public boolean insertIngredient(String name, int measureUnity) 
	{
		return ingredientsBusinessObject.insertIngredient(name,measureUnity);
	}

	public boolean insertCustomer(String name, String address, int city,String telephone) 
	{
		return customersBusinessObject.insertCustomer(name,address,city,telephone);
	}

	public Object[][] getRecipes() 
	{
		return recipesBusinessObject.getRecipes();
	}

	public Object[][] getPies() 
	{
		return piesBusinessObject.getPies();
	}

	public Object[] searchRecipeDetail(String name) 
	{
		return recipesBusinessObject.searchRecipeDetail(name);
	}

	public Object[] searchPieDetail(String name) 
	{
		return piesBusinessObject.searchPieDetail(name);
	}

}
